package com.huiyi.ai.swagger;

import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class SwaggerConfig {

    @Autowired
    private Swagger2ConfigProperties properties;

    @Bean
    public OpenAPI swaggerOpenApi() {

        Contact contact = new Contact();
        contact.setName(properties.getContactName());
        contact.setEmail(properties.getContactEmail());
        contact.setUrl(properties.getContactUrl());

        log.info("The springDoc swagger have been loaded successfully!");

        return new OpenAPI()
                .info(new Info().title(properties.getTitle())
                        .description(properties.getDescription())
                        .termsOfService(properties.getTermsOfServiceUrl())
                        .contact(contact)
                        .version("v1.0.0"))
                .externalDocs(new ExternalDocumentation()
                        .description("设计文档")
                        .url("https://siidoefeykb.feishu.cn/wiki/HZzjwXKk4iF3ZWkPNtMcURlOnAe?from=from_copylink"));
    }

}
